import Vue from 'vue'
import VueRouter from 'vue-router'
import IndexView from "@/views/IndexView";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/web',
  },
  {
    path: '/web', // 二级路由
    component: () => import('../views/IndexView.vue'),
    meta: {
      title: "首页"
    },
  },
  {
    path: "/login",
    component: () => import("../views/login/LoginPage.vue"),
    meta: {title: "登录"},
  },

  {/*首页*/
    path: '/article',
    component: () => import('../views/article/ArticleManagement.vue'),
    meta: {
      title: "文章"
    },
    children: [
      {
        path: "detail",
        component: () => import("../views/article/ArticleDetail"),
        meta: {title: "文章详情"},
      },
      {
        path: "write",
        component: () => import('../views/article/WriteArticle.vue'),
        meta: {title: "发表文章"},
      },
    ]
  },
  {/*首页*/
    path: 'user-center',
    component: () => import('../views/UserCenter/UserCenter.vue'),
    meta: {
      title: "个人中心"
    },
  },


  {
    path: "/hot",
    component: () => import("../views/ethnic/HotView"),
    meta: {title: "热门"},
  },
  {
    path: "/ethnic",

    component: () => import("../views/ethnic/EthnicManagement"),
    meta: {title: "民族"},
    children: [
      {
        path: "detail",
        component: () => import("../views/ethnic/EthnicDetail"),
        meta: {title: "民族详情"},
      },
      {
        path: "synopsis",
        component: () => import("../views/ethnic/EthnicSynopsis.vue"),
        meta: {title: "民族简介"},
      },
  ]
  },



  {
    path: "/error",
    component: () => import("../views/error/ErrorView"),
    meta: {title: "404"},
  },

  {
    path: "/userCenter",
    component: () => import("../views/UserCenter/UserCenter"),
    redirect: "/userCenter/details",
    meta: {title: "个人中心"},
    children: [
      {
        path: "details",
        component: () => import("../views/UserCenter/UserCenterDetails"),
        meta: {title: "个人信息"},
      },
      {
        path: "modifyHeadImage",
        component: () => import("../views/UserCenter/UserCenterModifyHeadImage"),
        meta: {title: "修改头像"},
      },
      {
        path: "review",
        component: () => import("../views/UserCenter/ReviewPage.vue"),
        meta: {title: "媒体审核"},
      }, {
        path: "myArticle",
        component: () => import("../views/UserCenter/UserCenterMyArticles"),
        meta: {title: "我的文章"},
      }, {
        path: "myCollection",
        component: () => import("../views/UserCenter/UserCenterMyCollection"),
        meta: {title: "我的收藏"},
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})


export default router
